package com.foreknow.elm.controller;

import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;

public class UserController {
    /**
     * 根据用户编号与密码查询用户信息
     * @param request
     * @return
     */
    public User getUserByIdByPass(HttpServletRequest request) {
        String userId = request.getParameter("userId" );
        String password = request.getParameter("password");
        User user = new User();
        UserService service = new UserServiceImpl();
        return service.getUserByIdByPass(userId,password);
    }

    /**
     * 根据用户编号查询用户表返回的行数
     * @param request
     * @return
     */
    public int getUserById(HttpServletRequest request) {
        String userId = request.getParameter("userId" );
        UserService service = new UserServiceImpl();
        return service.getUserById(userId);
    }

    /**
     * 向用户表中添加一条记录
     * @param request
     * @return
     */
    public int saveUser(HttpServletRequest request) {
        String userId = request.getParameter("userId" );
        String password = request.getParameter("password");
        String userName = request.getParameter("userName");
        String userSex = request.getParameter("userSex");
        UserService service = new UserServiceImpl();
        return service.saveUser(userId,password,userName,userSex);
    }


}
